var FM = {
    selector: '.flashMessages',
    fmCss: 'flash-messenger-',
    templateBegin: '<div class="flash-messenger __replacement__ ui-corner-all"><a href="javascript:nop();" onclick="javascript:FM.close(this);" class="fm-close"><span class="ui-icon ui-icon-closethick">close</span></a><ul>',
    templateEnd: '</ul></div>',
    itemBegin: '<li>',
    itemEnd: '</li>',
    itemsSelector: 'ul',
    
    add: function(level, msg) {
        var css = this.fmCss + level;
        if($(this.selector + ' .'+css).length == 0) {
            var html = this.templateBegin.replace('__replacement__', css+ ' hide');
            html += this.itemBegin + msg + this.itemEnd;
            html += this.templateEnd;
            $(this.selector).append(html);
            $(this.selector + ' .' + css).slideDown('slow');
        } else {
            var html = this.itemBegin + msg + this.itemEnd;
            $(this.selector + ' .' + css + ' ' + this.itemsSelector).append(html);
        }
    },
    close: function(el) {
        console.log(el);
        $(el).parent().slideUp();
    }
};